package com.ch;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName 子数组最大平均数I.java
 * @Description TODO
 * @createTime 2021年02月04日 11:29:00
 */
public class 子数组最大平均数I {
    public static void main(String[] args) {
        int []nums = {0,4,0,3,2};
        Solution643 s = new Solution643();
        s.findMaxAverage(nums,1);
    }
}


class Solution643 {
    public double findMaxAverage(int[] nums, int k) {
        double ans = 0;
        for(int i = 0;i<k;i++){
            ans += nums[i];
        }
        double temp = ans;
        for(int i=k;i  < nums.length; i++){
            temp = temp - nums[i - k] + nums[i];
            if(temp > ans)
                ans = temp;
        }
        return ans / k;
    }
}